﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>申请退款</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        html {
            font-size: 10px;
            text-size-adjust: 100%;
        }

        html, body {
            width: 100%;
            height: 100%;
        }

        .content {
            width: 100%;
            height: 100%;
            background: #ccc;
        }

        .ticket {
            width: 100%;
            overflow: hidden;
        }

            .ticket > h3 {
                height: 30px;
                line-height: 30px;
                padding: 10px;
                font-size: 1.5rem;
                font-weight: normal;
            }

        .ticket-detail {
            padding: 0 0 0 1.5rem;
            background: #fff;
        }

        .ticket-detail-item {
            height: 3.5rem;
            line-height: 3.5rem;
            border-top: 1px solid #ccc;
            font-size: 1.5rem;
            overflow: hidden;
        }

            .ticket-detail-item span {
                float: right;
            }

        .pr {
            padding-right: 4rem;
        }

        .ticket-detail-item .addon {
            display: inline-block;
            width: 3.5rem;
            height: 3.5rem;
            text-align: center;
            font-size: 3rem;
            font-style: normal;
            background: #62b900;
            cursor: pointer;
            color: #fff;
        }

        .addon.disable {
            opacity: 0.6;
            /*background: #00ccff;*/
        }

        .ticket-detail-item input {
            width: 4rem;
            height: 3.5rem;
            vertical-align: top;
            text-align: center;
            border: none;
        }

        .noborder {
            border: none;
        }

        .text-red {
            color: #ff0000;
        }

        .text-blod {
            font-weight: bold;
        }

        .ticket-submit {
            position: fixed;
            bottom: 0px;
            height: 50px;
            width: 100%;
            z-index: 9999;
            background-image: url(../images/ticket.png);
            background-repeat: repeat-x;
            margin-top: 5rem;
            text-align: center;
        }

            .ticket-submit span {
                margin-top: 5px;
                margin-bottom: 5px;
                display: inline-block;
                height: 40px;
                line-height: 40px;
                width: 8rem;
                text-align: center;
                border-radius: 15px;
                background: #62b900;
                color: #fff;
                font-size: 1.6rem;
            }
    </style>
</head>
<body>
    <div class="content">
        <div class="ticket">
            <h3>退票信息</h3>
            <div class="ticket-detail">
                <div class="ticket-detail-item noborder">
                    <label id="ticketName"></label>
                    <span id="singleTicketPrice" class="text-blod pr"></span>
                </div>
                <div class="ticket-detail-item">
                    <label>退票数量</label>
                    <span>
                        <i class="addon disable" id="minus">-</i>
                        <input id="number" value="1" />
                        <i class="addon" id="plus">+</i>
                    </span>
                </div>
                <div class="ticket-detail-item">
                    <label>退还总额</label>
                    <span id="refundTotal" class="text-red text-blod pr"></span>
                </div>
            </div>
        </div>
        <div class="ticket-submit">
            <span id="btnSubmit" class="text-blod">提 交</span>
        </div>
    </div>
    <script src="../javaScripts/zepto.min.js"></script>

    <script>
        var singlePrice = null;
        var ticketCategory = null;
        var orderId = null;
        var ticketName = null;

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return (r[2]); return null;
        };

        $(document).ready(function () {
            singlePrice = getQueryString("SingleTicketPrice");
            orderId = getQueryString("OrderId");
            ticketName = getQueryString("TicketName");
            while (ticketName.indexOf("%") > -1) {
                ticketName = decodeURI(ticketName);
            }

            if (singlePrice && orderId && ticketName) {
                $("#ticketName").html(ticketName);
                $(".text-blod.pr").html(parseFloat(singlePrice) + "元");
                $("#plus").on("click", f_plusClick);
                $("#minus").on("click", f_subClick);
                $("#btnSubmit").on("click", function () {

                    $.ajax({
                        type: "post",
                        url: '../WebService/OrderWebService.asmx/RefundTickets',
                        dataType: 'json',
                        data: {
                            orderId: orderId,
                            refundTicketNumber: f_getNumber()
                        },
                        success: function (result) {
                            if (result.IsSuccess) {
                                document.location.href = "MyOrderList.html";
                            } else {
                                alert(result.Message);
                            }
                        }
                    });
                });
                $("#number").on("change", f_numberOnChange);
            } else {
                alert("缺少必要的页面参数");
            }
        });

        function f_numberOnChange() {
            var num = $("#number");

            if (!isNaN(num.val())) {
                if (parseInt(num.val()) < 1) {
                    num.val(1);
                }
            } else {
                num.val(1);
            }

            f_showMoney();
        }

        function f_plusClick() {
            var num = $("#number");

            if (!isNaN(num.val())) {
                num.val(parseInt(num.val()) + 1);
            } else {
                num.val(1);
            }

            if (num.val() == 1) {
                $("#minus").addClass("disable");
            } else {
                $("#minus").removeClass("disable");
            }

            f_showMoney();
        }

        function f_subClick() {
            var num = $("#number");

            if (!isNaN(num.val())) {
                var value = parseInt(num.val());
                if (value > 1) {
                    num.val(value - 1);
                }
            } else {
                num.val(1);
            }

            if (num.val() == 1) {
                $("#minus").addClass("disable");
            } else {
                $("#minus").removeClass("disable");
            }

            f_showMoney();
        }

        function f_getNumber() {
            var num = $("#number");

            if (!isNaN(num.val())) {
                if (parseInt(num.val()) < 1) {
                    num.val(1);
                    return 1;
                }
                return parseInt(num.val());
            } else {
                num.val(1);
                return 1;
            }
        }

        function f_showMoney() {
            var num = $("#number");
            var count = 1;

            if (!isNaN(num.val())) {
                count = parseInt(num.val());
            } else {
                num.val(1);
            }

            if (singlePrice) {
                var totalFee = count * singlePrice;
                $("#refundTotal").html(totalFee + "元");
            }
        }
    </script>

</body>
</html>
